package com.dlee.mvc.util;

import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
* @author lida
* @since JDK1.7
* @history 2012-7-14 lida
**/
public class ClassUtils
{
    /**
     * 判断方法是否含有指定注解
     * @param method
     * @param annotation
     * @return
     */
    public static boolean isHaveAnnotation (Method method, Class annotation)
    {
        Annotation[] annotations = method.getAnnotations ();
        for (Annotation ann : annotations)
        {
            if (ann.annotationType ().equals (annotation))
            {
                return true;
            }
        }
        return false;
    }
    
    /**
     * 获取类上的注解
     * @param file
     * @param annotationScanPath
     * @return
     * @throws ClassNotFoundException
     */
    public static Annotation[] getAnnotation(File file,String annotationScanPath) throws ClassNotFoundException
    {
     // 抽取类的路径，再通过反射取类的实例
        String classFullPath = FileUtil.getClassFullName (file.getPath (), annotationScanPath);
        Class objClass = Class.forName (classFullPath);
        // 取类的注解类
        Annotation[] classAnnotation = objClass.getAnnotations ();
        return classAnnotation;
    }
}
